package com.share.sharedevice.controller;

import com.share.common.core.domain.R;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.page.TableDataInfo;
import com.share.sharedevice.entity.CabinetType;
import com.share.sharedevice.service.ICabinetTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "柜机类型接口管理")
@RestController
@RequestMapping("/cabinetType")
public class CabinetTypeController extends BaseController
{
    @Autowired
    private ICabinetTypeService cabinetTypeService;

    /**
     * 查询柜机类型列表
     */
    @Operation(summary = "查询柜机类型列表")
    @GetMapping("/list")
    public TableDataInfo list(CabinetType cabinetType)
    {
        startPage();
        List<CabinetType> list = cabinetTypeService.selectCabinetTypeList(cabinetType);
        return getDataTable(list);
    }

    @Operation(summary = "根据id查询")
    @GetMapping("/{id}")
    public R<CabinetType> byId(@PathVariable("id") Long id)
    {
        CabinetType cabinetType = cabinetTypeService.selectCabinetTypeById(id);
        return R.ok(cabinetType);
    }

    @Operation(summary = "添加")
    @PostMapping
    public R<CabinetType> add(@RequestBody CabinetType cabinetType)
    {
        cabinetTypeService.add(cabinetType);
        return R.ok();
    }

    /**
     * 修改
     */
    @Operation(summary = "修改")
    @PutMapping
    public R<CabinetType> update(@RequestBody CabinetType cabinetType)
    {
        cabinetTypeService.updatedevice(cabinetType);

        return R.ok();
    }

    /**
     * 删除
     */
    @Operation(summary = "删除")
    @DeleteMapping("/{ids}")
    public R<CabinetType> delete(@PathVariable("ids") List<Long> ids)
    {
        cabinetTypeService.deleteByIds(ids);
        return R.ok();
    }

}